var http = require('../../utils/http.js');
var util = require('../../utils/util.js');
var unionid = wx.getStorageSync('thisCode');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recharge:[],
    changeArr:['1'],
    imgUrl:http.imgUrl,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var unionid = wx.getStorageSync('thisCode');
    wx.showLoading({title: '加载中...',})
    http._post('WeChatPay/recharge_select_list',{unionid:unionid},res=>{
      let data = res.data;
      if(data.status == 1){
        let changeArr = this.data.changeArr
        this.setData({
          recharge:data.info.select_list,
          changeArr:changeArr,
          thisID:data.info.select_list[0].select_id
        })
      }
    },res=>{})
  },
  // 点击选择充值金额
  changeSty(e){
    let index = http.dataIndex(e)[0];
    let changeArr = http.forC(this.data.changeArr);
    let thisID = http.dataIndex(e)[1];
    console.log(index)
    changeArr[index] = '1';
    console.log(changeArr)
    this.setData({changeArr:changeArr,thisID:thisID});
  },
  // 点击充值
  okRechargeBtn(e){
    var unionid = wx.getStorageSync('thisCode');
    http._post('WeChatPay/recharge_to_pay',{
      unionid:unionid,
      select_id:this.data.thisID,
    },res=>{
      let data = res.data;
      if(data.status == 1){
        http.payFn(data,res=>{
          wx.reLaunch({
            url: '/pages/index/index'
          })
        },res=>{});
      }
    },res=>{})
  },  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  
  }
})